package 线程池.阻塞队列;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * @author: wh(1835734390 @ qq.com)
 * @date: 2023/8/15 11:21
 * @description:
 * @version:
 */
public class ForkJoinPoolWithBlockingQueueExample {
    public static void main(String[] args) {
        BlockingQueue<Task> queue = new LinkedBlockingQueue<>();

        // 创建生产者和消费者线程
        Producer producer = new Producer(queue);
        Consumer consumer = new Consumer(queue);

        // 启动生产者和消费者线程
        ExecutorService executorService = Executors.newFixedThreadPool(2);
        executorService.execute(producer);
        executorService.execute(consumer);

        // 等待一定时间后停止生产者和消费者线程
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }
        executorService.shutdownNow();
    }
}
